package com.egdd.video.controller;

import com.egdd.video.common.api.ApiResult;
import com.egdd.video.pojo.Category;
import com.egdd.video.service.iml.CategoryServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"分类管理"})
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    CategoryServiceImpl categoryService;

    private static final Logger LOGGER = LoggerFactory.getLogger(CategoryController.class);


    @ApiOperation("获取视频所有分类列表信息")
    @GetMapping(value = "listAll")
    public ApiResult getBrandList() {
        return ApiResult.success(categoryService.getAllCategory());
    }

    @ApiOperation("添加分类信息")
    @PostMapping(value = "insert")
    public ApiResult insert(@RequestBody Category category) {
        int count = categoryService.addCategory(category);
        if (count == 1) {
            return ApiResult.success(count);
        } else {
            return ApiResult.error("操作失败");
        }
    }

    @ApiOperation("更新分类信息")
    @PostMapping(value = "/update/{id}")
    public ApiResult updateBrand(@PathVariable("id") Integer id, @RequestBody Category category, BindingResult result) {
        int count = categoryService.updateCategory(id, category);
        if (count == 1) {
            return ApiResult.success(count);

        } else {
            return ApiResult.error("操作失败");

        }

    }
}
